import { defineConfig, loadEnv } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import path from 'path'

export default ({ mode }) => {
  const env = loadEnv(mode, process.cwd());
  return defineConfig({
    plugins: [uni()],   //可使用$ref{ refTransform: true }
    server: {
      open: false,
      port: 7777,
      https: false,
      proxy: {
        '/api': {
          /* 目标代理服务器地址 */
          target: env.VITE_ADMIN_PROXY_PATH,
          ws: true, // 是否启用 WebSocket
          changeOrigin: true, // 是否修改请求头中的 Origin 字段
          rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
    resolve: {
      alias: {//添加别名
        '@': path.resolve(__dirname, 'src')
      },
    }
  })
}